#!/bin/sh
# grep_static
# Builds from https://github.com/puppylinux-woof-CE/petbuilds

. ../../func

# GOES TO INITRD

URL=http://ftp.gnu.org/gnu/grep
SRC=grep
PKG=grep_static
VER=3.1
COMP=tar.xz
DESC=""
DEPS=
CAT=BuildingBlock
CWD=`pwd`

build() {
	cd ${SRC}-${VER}
	EXE=src/grep
	opts='--prefix=/usr --disable-nls --disable-perl-regexp'
	# http://buildroot-busybox.2317881.n4.nabble.com/PATCH-grep-fix-build-failure-for-musl-td84536.html
	if [ -d "$XPATH" ] ; then
		opts+=' --with-included-regex'
	fi
	_configure
	_make ${MKFLG} LDFLAGS=-static
	abort_if_file_not_found $EXE
	install -d -m 0755 $CWD/${PKG}-${VER}-${ARCH}/bin
	_install $EXE $CWD/${PKG}-${VER}-${ARCH}/bin
	cd -
}
	
package() {
	# add this recipe
	install -d -m 0755 ./${PKG}-${VER}-${ARCH}/build
	cat ${PKG}.petbuild > ./${PKG}-${VER}-${ARCH}/build/$PKG-build-recipe
	# move, don't package
	cp -a --remove-destination ./${PKG}-${VER}-${ARCH}/* ../../00_${ARCH}
	rm -r ${SRC}-${VER}
	rm -r ${PKG}-${VER}-${ARCH}
	echo "moved to initrd"
	echo "done!"
}

# main
retrieve ${SRC}-${VER}.${COMP}
[ "$DLD_ONLY" = "yes" ] && exit
extract ${SRC}-${VER}.${COMP}
build
package
